package com.szqhyxj.youxiangju.biz.activationReward.IncomeBreakdown;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.szqhyxj.youxiangju.BaseActivity;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.activationReward.IncomeBreakdownitem.fragmentactivityincome.EquipmentActivityAllitemFragment;
import com.szqhyxj.youxiangju.biz.activationReward.IncomeBreakdownitem.fragmentequipmentrevenue.EquipmentRevenueAllitemFragment;
import com.szqhyxj.youxiangju.biz.activationReward.IncomeBreakdownitem.fragmentquickincome.EquipmentQuickIncomeAllitemFragment;
import com.szqhyxj.youxiangju.biz.merchantHome.CustomViewPager;
import com.szqhyxj.youxiangju.sys.components.NavigationBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindColor;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by leung on 2018/11/22.
 */

public class IncomeBreakdownActivity extends BaseActivity implements IncomeBreakdownContarct.View {
    @BindView(R.id.navigationBar)
    NavigationBar navigationBar;
    @BindView(R.id.equipmentRevenueIcon)
    ImageView equipmentRevenueIcon;
    @BindView(R.id.equipmentRevenueTitle)
    TextView equipmentRevenueTitle;
    @BindView(R.id.equipmentRevenueArea)
    LinearLayout equipmentRevenueArea;
    @BindView(R.id.quipmentRevenueIcon)
    ImageView quipmentRevenueIcon;
    @BindView(R.id.quipmentRevenueTitle)
    TextView quipmentRevenueTitle;
    @BindView(R.id.quipmentRevenueArea)
    LinearLayout quipmentRevenueArea;
    @BindView(R.id.activityIncomeIcon)
    ImageView activityIncomeIcon;
    @BindView(R.id.activityIncomeTitle)
    TextView activityIncomeTitle;
    @BindView(R.id.activityIncomeArea)
    LinearLayout activityIncomeArea;
    @BindView(R.id.viewpager)
    CustomViewPager container;
    @BindColor(R.color.textad)
    int colorNormal;
    @BindColor(R.color.white)
    int colorSelected;
    @BindView(R.id.arrow1)
    TextView arrow1;
    @BindView(R.id.arrow2)
    TextView arrow2;
    @BindView(R.id.arrow3)
    TextView arrow3;
    private List<Fragment> fragments = new ArrayList<>();
    IncomeBreakdownPresentner presentner;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_income_breakdown);
        ButterKnife.bind(this);
        presentner = new IncomeBreakdownPresentner(this);
        presentner.init();

    }

    @Override
    public void showAll() {
        fragments.clear();
        fragments.add(EquipmentRevenueAllitemFragment.newInstance());
        fragments.add(EquipmentQuickIncomeAllitemFragment.newInstance());
        fragments.add(EquipmentActivityAllitemFragment.newInstance());
        container.setAdapter(new IncomeFragmentsContainer(getSupportFragmentManager(), fragments));
        container.setOffscreenPageLimit(3);
    }

    @Override
    public void showEquipment() {
        container.setCurrentItem(0, false);
        reset();
        equipmentRevenueIcon.setImageResource(R.mipmap.shebeishouyi);
        equipmentRevenueTitle.setTextColor(colorSelected);
        arrow1.setVisibility(View.VISIBLE);
        arrow2.setVisibility(View.GONE);
        arrow3.setVisibility(View.GONE);
    }

    @Override
    public void showQuick() {
        container.setCurrentItem(1, false);
        reset();
        quipmentRevenueIcon.setImageResource(R.mipmap.kuaijieshouyi);
        quipmentRevenueTitle.setTextColor(colorSelected);
        arrow1.setVisibility(View.GONE);
        arrow2.setVisibility(View.VISIBLE);
        arrow3.setVisibility(View.GONE);
    }

    @Override
    public void showActivity() {
        container.setCurrentItem(2, false);
        reset();
        activityIncomeIcon.setImageResource(R.mipmap.huodongshouyi);
        activityIncomeTitle.setTextColor(colorSelected);
        arrow1.setVisibility(View.GONE);
        arrow2.setVisibility(View.GONE);
        arrow3.setVisibility(View.VISIBLE);
    }

    private void reset() {
        equipmentRevenueIcon.setImageResource(R.mipmap.shebeishouyi_01);
        quipmentRevenueIcon.setImageResource(R.mipmap.kuaijieshouyi_01);
        activityIncomeIcon.setImageResource(R.mipmap.huodongshouy_01);

        equipmentRevenueTitle.setTextColor(colorNormal);
        quipmentRevenueTitle.setTextColor(colorNormal);
        activityIncomeTitle.setTextColor(colorNormal);

    }

    @OnClick({R.id.equipmentRevenueArea, R.id.quipmentRevenueArea, R.id.activityIncomeArea})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.equipmentRevenueArea:
                presentner.setEquipment();
                break;
            case R.id.quipmentRevenueArea:
                presentner.setQuick();
                break;
            case R.id.activityIncomeArea:
                presentner.setActivity();
                break;
        }
    }
}
